Description:
MIC detects situations when a method may return values of several incompatible types and its result is cast to one of them without a type check. Such situations may cause a class cast exception at runtime.
Incorrect:
MyRecord = class
private id:integer;
public function getId():TObject;
function GetHashCode():Integer;override;
end;
...
function MyRecord.getId():TObject;
begin
if id = -1 then
begin
result := nil;
exit;
end;
result := TObject(id);
end;
function MyRecord.GetHashCode():integer;
begin
result := integer(getId());
end;
Correct:
function MyRecord.GetHashCode():integer;
var o:TObject;
begin
o := getId();
if o is integer then
result := integer(o)
else
result := 0;
end;